<template>
  <div>
    <p>车辆管理</p>
    <div class="manage_car">
      <el-table :data="data" style="width: 100%" height="850px">
        <el-table-column label="车辆图片" width="100">
          <template slot-scope="scope">
            <el-image :src="scope.row.car_img" />
          </template>
        </el-table-column>
        <el-table-column label="车辆名称" width="90">
          <template slot-scope="scope">
            {{ scope.row.car_name }}
          </template>
        </el-table-column>
        <el-table-column label="车辆特点" width="150">
          <template slot-scope="scope">
            {{ scope.row.car_feature }}
          </template>
        </el-table-column>
        <el-table-column label="车辆类型" width="100">
          <template slot-scope="scope">
            {{ scope.row.car_type }}
          </template>
        </el-table-column>
        <el-table-column label="车辆动力" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_power }}
          </template>
        </el-table-column>
        <el-table-column label="车辆座位" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_seat }}
          </template>
        </el-table-column>
        <el-table-column label="车辆评分" width="80">
          <template slot-scope="scope"> {{ scope.row.car_score }}分 </template>
        </el-table-column>
        <el-table-column label="车辆价格" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_price }}￥/天
          </template>
        </el-table-column>
        <el-table-column label="油箱容量" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_tank }}
          </template>
        </el-table-column>
        <el-table-column label="是否热销" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_ishot | isHot }}
          </template>
        </el-table-column>
        <el-table-column label="变速箱" width="80">
          <template slot-scope="scope">
            {{ scope.row.car_speedbox }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.row.car_id, scope.row)"
            >
              修改
            </el-button>

            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row.car_id, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        feature: "",
        score: "",
        price: "",
      },
      formLabelWidth: "80px",
    };
  },
  mounted() {
    this.getdata();
  },
  methods: {
    // 获取车辆
    getdata() {
      this.axios.post("/admin/agetdatacar").then((res) => {
        // console.log(res.data.data);
        this.data = res.data.data;
      });
    },
    // 修改车辆
    handleEdit(index, row) {
      // console.log(index, row);
      this.$router.push(`updatecar/${index}`)
    },
    // 删除车辆
    handleDelete(index, row) {
      // console.log(index, row);

      this.$confirm("此操作讲永久删除车辆信息!是否删除车辆?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.axios.post("/admin/deletecar", `id=${index}`).then((res) => {
            // console.log(res);
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getdata()
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  filters: {
    isHot: function (value) {
      return (value == 1 && "热销") || (value == 0 && "正常");
    },
  },
};
</script>

<style lang="scss" scoped>
p {
  margin: 0;
  padding: 0;
  font-size: 30px;
  padding-left: 10px;
  padding: 15px 0px 15px 10px;
}
</style>
